from PIL import Image

# 加载图片
image = Image.open('test.jpg')

# 缩放图片
width, height = image.size
aspect_ratio = height / width
new_width = 50
new_height = 50
image = image.resize((new_width, new_height))

# 转换为灰度图像
image = image.convert('L')

# ASCII字符
ASCII_CHARS = [' ', '.', ':', '-', '=', '+', '*', '#', '%', '@', 'W', 'B', '$', '&', '8', 'O', 'M', '#', 'D', 'N', 'H', 'Q', 'S', 'U', 'K', 'X', 'Z']

# 将每个像素转换为ASCII字符
ascii_image = ''
pixels = image.getdata()
for pixel in pixels:
    ascii_image += ASCII_CHARS[int(pixel / 10)]

# 分割每一行
rows = [ascii_image[i:i+new_width] for i in range(0, len(ascii_image), new_width)]

# 输出banner
banner = '\n'.join(rows)
print(banner)
